<?php

namespace Backend\Controller;
use Think\Controller;

class  ApplyController extends  BaseController
{
    public  function  index(){

        $model =D('Apply');
        $data=$model ->get_apply();

        $this->assign(array(
            'data' => $data['data'],
            'page' => $data['page'],
        ));

        $this->display('index');
    }
    public  function  create(){

        $data=$_POST;
        if($data)
        {
            $model = D('Apply');
            if (!$data = $model->create()) {
                $this->ajaxReturn(['status' => 'failed', 'msg' => $model->getError()]);
                exit;
            }else{

                if($result = $model->add())
                {

                    $this->ajaxReturn(['status' => 'success', 'msg' => '添加成功！']);
                    exit;
                }else{
                    $this->ajaxReturn(['status' => 'failed', 'msg' =>$model->getError() ]);
                    exit;
                }
            }
        }

            $data =D('Apply')->field('id,apply_classify')->order('id')->select();
            $this->assign('data',$data);
            $this->display();

    }
    public  function  delete(){
        if(!$_POST['id']){
            $this->ajaxReturn(['status' => 'failed', 'msg' => '操作有误，重新选择！']);
            die;

        }
        $where ='id in('.trim($_POST['id'],',').')';
        $model = D('Apply');
        $res =$model->where($where)->delete();
        //echo $model->getLastSql();exit;
        if ($res) {
            $this->ajaxReturn(['status' => 'success', 'msg' => '操作成功！']);
        } else {
            $this->ajaxReturn(['status' => 'failed', 'msg' => '操作失败！']);
        }
    }

    public function apply_type(){
        $data =D('Apply')->field('id,apply_classify')->order('id')->select();
        $this->assign('data',$data);
        $this->display();
    }


}